import os, time
from selenium import webdriver

chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"  # 浏览器驱动位置
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
file_path = 'file:///' + os.path.abspath('checkbox.html')
driver.get(file_path)
# 注意这里elements后面有s
# 通过标签找
# inputs = driver.find_elements_by_tag_name('input')
# for i in inputs:
#     if i.get_attribute('type') == 'checkbox':
#         i.click()
#         time.sleep(1)

# 通过Xpath
# inputs = driver.find_elements_by_xpath("//input[@type='checkbox']")
# 通过css
inputs = driver.find_elements_by_css_selector('input[type=checkbox')
for i in inputs:
    i.click()
    time.sleep(1)
# 打印复选框数量
print(len(inputs))
# 把最后一个框点一下
inputs.pop().click()
time.sleep(1)
driver.quit()
